<!--未分配任务-->
<template>
  <div class="task-assign">
    <!-- 顶部标题栏组件 -->
    <top-header></top-header>

    <div class="task-content">
      <van-search v-model="searchContent" placeholder="请输入搜索关键词" input-align="center" @input="onInput" />
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
        <van-cell v-for="(item, index) in serList" :key="index" @click="toDetail(item)">
          <template #title>
            <div class="van-title">
              <div class="van-top">
                <van-tag plain type="primary" color="burlywood">{{ index + 1 }}</van-tag>
                <span class="custom-title">{{ item.date | filterTime }}</span>
              </div>
              <span class="cust-title">{{ item.cust_name }}</span>
            </div>
          </template>
          <template #label>
            <van-tag plain type="primary" color="burlywood">{{ item.createBy }}</van-tag>
            <span class="custom-title">{{ item.request }}</span>
          </template>
        </van-cell>
      </van-list>
    </div>

    <!-- 路由导航组件 -->
    <nav-bar></nav-bar>
  </div>
</template>

<script>
import { TopHeader, NavBar } from '@/components'
import { getMySerList } from '@/request/api'
export default {
  name: 'TaskAssign',
  components: {
    TopHeader,
    NavBar
  },
  filters: {
    filterTime (val) {
      return val.slice(0, 10)
    }
  },
  data () {
    return {
      searchContent: '',
      serList: [], // 我的任务数据
      serCount: 0, // 我的日志数据总量
      loading: false,
      finished: false,
      pageIndex: 0
    }
  },
  created () {
    const param = { staffId: '', page: this.pageIndex, 'pageCount': 10, status: 'Default' }
    // 获取我的任务数据
    getMySerList(param).then(res => {
      console.log(res)
      this.serList = res.result.mySer
      this.serCount = res.result.count
    })
  },
  methods: {
    onInput (value) {
      this.searchContent = value
      this.serList = []
      this.pageIndex = 0
      this.finished = false
      const param = { staffId: '', 'page': this.pageIndex, pageCount: 10, status: 'Default', custName: this.searchContent }
      // 获取我的任务数据
      getMySerList(param).then(res => {
        this.serList = res.result.mySer
        this.serCount = res.result.count
      })
    },
    onLoad () {
      // 异步更新数据
      setTimeout(() => {
        this.pageIndex++
        const param = { staffId: '', 'page': this.pageIndex, pageCount: 10, status: 'Default', custName: this.searchContent }
        getMySerList(param).then(res => {
          this.serList = [...this.serList, ...res.result.mySer]
          this.serCount = res.result.count
        })
        // 加载状态结束
        this.loading = false
        // 数据全部加载完成
        if (10 * (this.pageIndex + 1) >= this.serCount) {
          this.finished = true
        }
      }, 1000)
    },
    toDetail (value) {
      console.log('跳转到详情页', value)
      sessionStorage.setItem('SER_LIST', JSON.stringify(value))
      sessionStorage.setItem('SET_ASSIGN', true)
      sessionStorage.setItem('History_Status', false)
      this.$router.push({ path: '/taskDetail' })
    }
  }
}
</script>

<style scoped lang="less">
.task-assign {
  width: 100%;
  height: 100%;
  .task-content {
    height: calc(100% - 2.7rem);
    display: flex;
    flex-direction: column;
    .van-search {
      border: 1px solid #ebedf0;
    }
    .van-list {
      flex: 1;
      overflow-y: auto;
      overflow-x: hidden;
      .van-cell {
        .van-cell__title {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          .van-title {
            display: flex;
            .van-top {
              flex: 1;
            }
            .cust-title {
              flex: 1;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              text-align: right;
            }
          }
          .van-tag {
            margin-right: 2px;
          }
          .van-cell__label {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
    }
  }
}
</style>
